<template>
	<div class="common_tabs_container">
		<el-tabs type="card" class="custom_top" v-model="activeName">
			<el-tab-pane v-for="(item, index) in configEnumData" :key="index" :label="item.msg" :name="item.value"></el-tab-pane>
		</el-tabs>
		<sw-common-frame :loading="loading">
			<template slot="button">
				<el-button size="small" type="primary" icon="el-icon-plus" @click="handleOpenDialog()">新增</el-button>
			</template>
			<template slot="query">
				<el-form size="small" inline>
					<el-form-item><el-input v-model="queryData.name" clearable placeholder="请输入配置名称"></el-input></el-form-item>
					<el-form-item><el-button type="primary" @click="queryTableData">查询</el-button></el-form-item>
				</el-form>
			</template>
			<template slot="table">
				<el-table size="medium" :data="tableData" stripe height="100%">
					<el-table-column type="index" label="序号" align="center" width="48"></el-table-column>
					<el-table-column prop="name" label="配置名称" min-width="120"></el-table-column>
					<el-table-column prop="filed13" label="配置标识" min-width="200">
						<template slot-scope="{ row }">
							<template v-if="row.filed1 !== '8'">{{ row.filed13 }}</template>
							<el-button v-else size="medium" type="text" @click="handleConfigChild(row)">{{ row.filed13 }}</el-button>
						</template>
					</el-table-column>
					<el-table-column label="配置标识" min-width="130" :formatter="returnConfigType"></el-table-column>
					<el-table-column prop="content" label="配置说明" min-width="200"></el-table-column>
					<el-table-column prop="createName" label="创建人" width="120"></el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="160"></el-table-column>
					<el-table-column label="操作" width="90">
						<template slot-scope="{ row }">
							<el-button size="medium" type="text" @click="handleOpenDialog(row.id)">修改</el-button>
							<el-button size="medium" type="text" @click="handleDeleteData(row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</template>
			<template slot="page">
				<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
			</template>
			<form-dialog v-model="formDialog" :type="activeName" :data-id="dataId" @refresh="queryTableData()"></form-dialog>
			<child-drawer v-model="drawerVisible" :data="drawerData" @refresh="queryTableData()"></child-drawer>
		</sw-common-frame>
	</div>
</template>

<script>
import formDialog from './form';
import childDrawer from './drawer';
import listMixins from '@/mixins/listMixins';
import { queryConfigPageList, deleteConfig } from '@/api/system/tbSysConfig';
export default {
	mixins: [listMixins],
	components: { formDialog, childDrawer },
	data() {
		return {
			pageName: '配置',
			activeName: '13',
			drawerData: {},
			drawerVisible: false
		};
	},
	computed: {
		configEnumData() {
			return this.dictEnums['SYSTEM_BASE_CONFIG'];
		},
		listFunction() {
			return eval(queryConfigPageList);
		},
		deleteFunction() {
			return eval(deleteConfig);
		},
		requestParams() {
			return { ...this.queryData, type: this.activeName };
		}
	},
	watch: {
		activeName: {
			handler() {
				this.queryTableData();
			},
			immediate: true
		}
	},
	methods: {
		//返回配置类型
		returnConfigType(data) {
			let info = this.dictConfigType.find((n) => n.type === data.filed1);
			return !info ? '--' : info.label;
		},

		handleConfigChild(data) {
			this.drawerData = { ...data };
			this.drawerVisible = true;
		}
	}
};
</script>
